# - Find the ICU includes and library
# This module defines
#  ICU_INCLUDE_DIRS: Where to find unicode/ustring.h
#  ICU_LIBRARIES: The libraries to link against to use ICU
#  ICU_FOUND: ICU has been found

find_program(ICU_CONFIG icu-config)
if(ICU_CONFIG)
  execute_process(
    COMMAND ${ICU_CONFIG} --ldflags
    OUTPUT_VARIABLE ICU_LIBRARY
    OUTPUT_STRIP_TRAILING_WHITESPACE
  )
  string(STRIP ${ICU_LIBRARY} ICU_LIBRARY)
endif()

find_path(ICU_INCLUDE_DIR unicode/ustring.h
  ${CMAKE_INSTALL_PREFIX}/include
  /usr/local/include
  /usr/include
)

if(ICU_INCLUDE_DIR AND ICU_LIBRARY)
  set(ICU_INCLUDE_DIRS ${ICU_INCLUDE_DIR})
  set(ICU_LIBRARIES ${ICU_LIBRARY})
  set(ICU_FOUND YES)
else()
  set(ICU_FOUND NO)
endif()

if(ICU_FOUND)
  if(NOT ICU_FIND_QUIETLY)
    message(STATUS "Found ICU!")
  endif()
else()
  if(ICU_FIND_REQUIRED)
    message(FATAL_ERROR "Could not find ICU library")
  endif()
endif()

mark_as_advanced(ICU_CONFIG ICU_INCLUDE_DIR ICU_LIBRARY)
